using CodeSaude.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace CodeSaude.Infrastructure.Data.EntityConfig
{
    public class cep_logradouroMap : EntityTypeConfiguration<cep_logradouro>
    {
        public cep_logradouroMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.uf)
                .IsRequired()
                .HasMaxLength(2);

            this.Property(t => t.logradouro)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.complemento)
                .HasMaxLength(200);

            this.Property(t => t.cep)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.tipo_logradouro)
                .IsRequired()
                .HasMaxLength(72);

            this.Property(t => t.log_sta_tlo)
                .HasMaxLength(50);

            this.Property(t => t.logradouro_abrev)
                .HasMaxLength(72);

            // Table & Column Mappings
            this.ToTable("cep_logradouro");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.uf).HasColumnName("uf");
            this.Property(t => t.id_municipio).HasColumnName("id_municipio");
            this.Property(t => t.id_bairro).HasColumnName("id_bairro");
            this.Property(t => t.id_bairro_fim).HasColumnName("id_bairro_fim");
            this.Property(t => t.logradouro).HasColumnName("logradouro");
            this.Property(t => t.complemento).HasColumnName("complemento");
            this.Property(t => t.cep).HasColumnName("cep");
            this.Property(t => t.tipo_logradouro).HasColumnName("tipo_logradouro");
            this.Property(t => t.log_sta_tlo).HasColumnName("log_sta_tlo");
            this.Property(t => t.logradouro_abrev).HasColumnName("logradouro_abrev");

            // Relationships
            this.HasOptional(t => t.cep_bairro)
                .WithMany(t => t.cep_logradouro)
                .HasForeignKey(d => d.id_bairro);
            this.HasRequired(t => t.cep_municipio)
                .WithMany(t => t.cep_logradouro)
                .HasForeignKey(d => d.id_municipio);

        }
    }
}
